import { ElNotification, ElMessageBox, ElMessage, ElLoading } from 'element-plus'

let downloadLoadingInstance

function notice(title = '空白提示', message, type = 'success', duration = 5 * 1000) {
    ElNotification({ title, message, type, duration });
}

function msg(message = '操作成功', type = 'success', title = '空白提示', duration = 5 * 1000) {
    ElMessage({ title, message, type, duration });
}

async function confirm(title = '请选择', message, confirmButtonText, type = 'warning') {
    await ElMessageBox.confirm(message, title, { confirmButtonText, cancelButtonText: '取消', type })
}

function loading(stopTag = false) {
    if (stopTag) {
        downloadLoadingInstance.close();
        return;
    }
    downloadLoadingInstance = ElLoading.service({ text: "正在下载数据，请稍候", background: "rgba(0, 0, 0, 0.7)", })
}

export default {
    notice,
    msg,
    confirm,
    loading
}